﻿using System;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace RoleEditer
{
	public partial class SpiriteFrame : UserControl,IDisposable
	{
        static SolidColorBrush selectColorBrush = new SolidColorBrush(Colors.Blue);
        static SolidColorBrush defaultColorBrush = new SolidColorBrush(Colors.Black);
		public SpiriteFrame()
		{
			InitializeComponent();
		}
        //设置是否选择
        public bool IsSelected
        {
            set
            {
                if (value)
                    selected.Stroke = selectColorBrush;
                else
                    selected.Stroke = defaultColorBrush;
            }
        }
        //快速设置帧的图片来源
        public ImageSource FrameSource
        {
            get{return image.Source;}
            set
            {
                image.Source = value;
            }
        }
        //帧设定
        private Image frame = null;
        //外部直接设定帧的属性
        public Image Frame
        {
            set
            {
                if (value == null)
                    this.LayoutRoot.Children.RemoveAt(0);
                else
                    this.LayoutRoot.Children.Insert(0, value);
                frame = null;
            }
            get { return frame; }
        }

        public void Dispose()
        {
            Frame = null;
            LayoutRoot.Children.Clear();
        }
        //点击当前帧触发
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (ANIPlay.Current.IsCanControl == false)
                return;
            else
            {
                ANIPlay.Current.PlayFramesIndex = MainPage.Current.GetFrameIndexFromItem(this);
            }
            base.OnMouseLeftButtonDown(e);
        }
    }
}